package pac;

public class Student extends Person {
	private String Zhuanye;
    private String Minzu;
    private Course[] courses;
    public Student() {
        courses = new Course[3];
    }
    public Student(int stuId,String stuName,String sex,String minzu,String zhuanye) {
        this.Id = stuId;
        this.Name = stuName;
        this.sex = sex;
        this.Minzu = minzu;
        this.setZhuanye(zhuanye);
        courses = new Course[3];
    }

	public String getZhuanye() {
		return Zhuanye;
	}
	public void setZhuanye(String zhuanye) {
		Zhuanye = zhuanye;
	}
	public String getMinzu() {
		return Minzu;
	}
	public void setMinzu(String minzu) {
		Minzu = minzu;
	}
    public boolean Selected(Course course){
        boolean cnt=false;
        for(Course c:courses){
            if(c==course){
                cnt=true;
                break;
            }
        }
        return cnt;
    }
    public boolean Null(Course course){
        boolean cnt=false;
        for(Course c:courses){
            if(c==null){
                cnt=true;
                break;
            }
        } 
        return cnt;
    }
    
    public boolean addCourse(Course course){
        boolean cnt=false;
        if(!Selected(course)&&Null(course)){
            for(int i=0;i<this.courses.length;i++){
                if(courses[i]==null){
                    courses[i]=course;
                    course.addStudent(this);     
                    cnt=true;
                    break;
                }
            }
        }
        return cnt;
    }
    
    public boolean removeCourse(Course course){
        boolean cnt=false;
        if(Selected(course)){
            for(int i=0;i<this.courses.length;i++){
                if(courses[i]==course){
                    courses[i]=null;
                    course.removeStudent(this); 
                    cnt=true;
                    break;
                }
            }
        }
        return cnt;
    }
    
    public void displayCourse(){
//        System.out.println(this.stuName+"  "+this.stuId+"  "+this.sex+"  "+this.Minzu+"  "+this.Zhuanye);
    	 System.out.println(this.Name+"  "+this.Id+"  "+this.sex+"  "+this.Minzu+"  "+this.Zhuanye);
        for(Course c:courses){
            if(c!=null){
                System.out.print("课程编号:"+c.getId()+"\n所选课程："+c.getName()+"\n上课地点:"+c.getDestination()+"\n上课时间:"+c.getTime()+"\n");
            }
        }
        System.out.println();
    }

}
